import React, { Component } from 'react'
import axios from 'axios'
import{
    HotTaskContainer
} from '../../StyledHome'


const arr = [
    {
        tid:100,
        tname:"高数补习",
        tcontent:"帮忙一对一补习高数，补习内容是数列，微积分",
        rctime:'2019-10-26 20:00-22:00',
        price:5


    },
    {
        tid:101,
        tname:"新概念英语补习",
        tcontent:"帮忙一对一补习英语，补习内容是阅读理解",
        rctime:'2019-10-26 20:00-21:00',
        price:5
    },
    {
        tid:102,
        tname:"算法补习",
        tcontent:"帮忙一对一补习算法，补习内容是各种排序算法",
        rctime:'2019-10-25 19:00-21:00',
        price:5
    },
    {
        tid:103,
        tname:"Vue补习",
        tcontent:"帮忙一对一补习Vue全家桶",
        rctime:'2019-10-25 09:00-22:00',
        price:5
    },
    {
        tid:104,
        tname:"React补习",
        tcontent:"帮忙一对一补习React路由",
        rctime:'2019-10-25 15:00-22:00',
        price:5
    },
]

export default class HotTask extends Component {
    state = {
       
        hotTaskData:[]
    }
    componentDidMount(){
        fetch("/Legang/task/findhot",{   
         method:"POST",
         headers:{
             "Content-type":"application/x-www-form-urlencoded",
             },
         })   
         .then(response => response.json())
         .then(result=>{
            //  console.log(result.data)
             this.setState({
                hotTaskData : result.data
             }
             )
         })  
     }

  
    render() {
      
        return (
            <HotTaskContainer>
               <div>
            
                   <ul>
                      {
                      (this.state.hotTaskData!==[]? this.state.hotTaskData:arr).map((value,index)=>(
                        // this.state.hotTaskData.map((value,index)=>(
                            //   console.log(value)
                                <li onClick={()=>this.onClickTask(value.tid)} key={value.tid}>
                          
                          
                                <div className="taskLeft">
                                    <h4>{value.tname}</h4>
                                    <div className="taskContent">{value.tcontent}</div>
                                    <div className="taskTime">
                                    <span>{value.rctime}</span> 
                                    </div>
                                </div>
                                <div className="taskRight">
                                    <span>￥</span> <span>{value.price}</span>
                                </div>
                          </li>
                          ))
                      }
                   </ul>
               </div>
            </HotTaskContainer>
        )
    }
    onClickTask(tid){
        console.log(tid)
        this.props.history.push({pathname:"/hallChildRouter/taskInfo/" + tid});
        // this.props.history.push({pathname :'/taskInfo',query:{tag}})
    }

   
}
